package com.lyn.domain;

import com.jfinal.kit.PathKit;
import com.jfinal.kit.Prop;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
import com.jfinal.plugin.activerecord.dialect.OracleDialect;
import com.jfinal.plugin.activerecord.generator.Generator;
import com.jfinal.plugin.druid.DruidPlugin;

public class _Generator {
	
	public static DruidPlugin getDataSource() {
		Prop p = PropKit.use("application-local.properties");
		DruidPlugin druidPlugin = new DruidPlugin(
				p.get("datasource.url"), p.get("datasource.username"),
				p.get("datasource.password"), p.get("datasource.driver"));
		druidPlugin.setValidationQuery("select 1 from dual");
		druidPlugin.start();
		return druidPlugin;
}


	public static void main(String[] args) {
		// base model 所使用的包名
		String baseModelPackageName = "com.lyn.domain";
		// base model 文件保存路径
		String baseModelOutputDir = PathKit.getWebRootPath() + "/src/main/java/com/lyn/domain";
		
		// model 所使用的包名 (MappingKit 默认使用的包名)
		String modelPackageName = "com.lyn.domain";
		// model 文件保存路径 (MappingKit 与 DataDictionary 文件默认保存路径)
		String modelOutputDir = baseModelOutputDir;
		
		DruidPlugin druid = getDataSource();

		// 创建生成器
		Generator generator = new Generator(druid.getDataSource(), baseModelPackageName, baseModelOutputDir, modelPackageName, modelOutputDir);
		generator.setDialect(new OracleDialect());
		generator.addExcludedTable("TBL_DATA_HYYDFLB_12, TBL_DATA_HYYDFLB_15, TBL_DATA_HYYDFLB_18, TBL_DATA_HYYDFLB_21, TBL_DATA_HYYDFLB_24");
		//generator.addIncludedTable("ads_oclife_finance_ts, ads_oclife_flow_ts");
		//generator.addExcludedTable("ads_oclife_finance_ts, ads_oclife_flow_ts");
		// 设置是否在 Model 中生成 dao 对象
		generator.setGenerateDaoInModel(true);
		// 设置是否生成字典文件
		generator.setGenerateDataDictionary(false);
		// 设置需要被移除的表名前缀用于生成modelName。例如表名 "osc_user"，移除前缀 "osc_"后生成的model名为 "User"而非 OscUser
		//generator.setRemovedTableNamePrefixes("");
		
		// 生成
		generator.generate();

		druid.stop();
	}





}




